package com.isoftstone.project.facilities.management.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.isoftstone.project.facilities.management.domain.FacilitiesManagement;
import com.isoftstone.project.facilities.management.service.IFacilitiesManagementService;
import com.isoftstone.framework.controller.BaseController;
import com.isoftstone.framework.domain.Page;
import com.isoftstone.framework.domain.Tidings;
import com.isoftstone.common.utils.ExcelUtil;
import com.isoftstone.framework.domain.PageData;

/**
 * 设备串口协议参数设置Controller
 *
 * @author guoX
 * @date 2021-02-02
 */
@Controller
@RequestMapping("/facilities/management")
public class  FacilitiesManagementController extends BaseController {
    private String prefix = "facilities/management";

    @Autowired
    private IFacilitiesManagementService facilitiesManagementService;

    @RequiresPermissions("facilities:management:view")
    @GetMapping()
    public String management() {
        return prefix + "/management_list";
    }

    /**
     * 查询设备串口协议参数设置列表
     */
    @RequiresPermissions("facilities:management:list")
    @PostMapping("/facilitiesManagementlistPage")
    @ResponseBody
    public Object getfacilitiesManagementlistPage(Page page) {
        PageData pd = this.getPageData();
        page.setPd(pd);
        List<FacilitiesManagement> list = facilitiesManagementService.getFacilitiesManagementlistPage(page);
        return Tidings.success(page.getTotalResult(), list);
    }


    /**
     * 导出设备串口协议参数设置列表
     */
    @RequiresPermissions("facilities:management:export")
    @PostMapping("/exportFacilitiesManagement")
    @ResponseBody
    public Object exportFacilitiesManagement(Page page) {
        PageData pd = this.getPageData();
        page.setPd(pd);
        page.setEntityOrField(false);
        List<FacilitiesManagement> list = facilitiesManagementService.getFacilitiesManagementlistPage(page);
        ExcelUtil<FacilitiesManagement> util = new ExcelUtil<FacilitiesManagement>(FacilitiesManagement. class);
        return util.exportExcel(list, "management");
    }

    /**
     * 新增设备串口协议参数设置
     */
    @GetMapping("/addFacilitiesManagement")
    public String addFacilitiesManagement() {
        return prefix + "/management_add";
    }


    /**
     * 新增保存设备串口协议参数设置
     */
    @RequiresPermissions("facilities:management:add")
    @PostMapping("/addFacilitiesManagement")
    @ResponseBody
    public Object insertFacilitiesManagement(FacilitiesManagement facilitiesManagement) {
        facilitiesManagementService.insertFacilitiesManagement(facilitiesManagement);
        return Tidings.success();

    }

    /**
     * 修改设备串口协议参数设置
     */
    @GetMapping("/toEditFacilitiesManagement")
    public String toEditFacilitiesManagement(String managementId, ModelMap mmap) {
        FacilitiesManagement facilitiesManagement =facilitiesManagementService.getFacilitiesManagementById(managementId);
        mmap.put("facilitiesManagement", facilitiesManagement);
        return prefix + "/management_edit";
    }

    /**
     * 修改保存设备串口协议参数设置
     */
    @RequiresPermissions("facilities:management:edit")
    @PostMapping("/updateFacilitiesManagement")
    @ResponseBody
    public Object updateFacilitiesManagement(FacilitiesManagement facilitiesManagement) {
        facilitiesManagementService.updateFacilitiesManagement(facilitiesManagement);
        return Tidings.success();
    }

    /**
     * 删除设备串口协议参数设置
     */
    @RequiresPermissions("facilities:management:remove")
    @PostMapping("/deleteFacilitiesManagement")
    @ResponseBody
    public Object deleteFacilitiesManagement(String managementId) {
        facilitiesManagementService.deleteFacilitiesManagementByIds(managementId);
        return Tidings.success();
    }

}
